<template>
    <div class="samebox">
        <div class="q_xxpxjl">
            <img src="" alt="">
            <div> 著作、论文及重要技术报告登记</div>
        </div>
        <div class="q_zssx" style="text-align: right">
            <el-row>
                <el-button type="primary" size="medium" class="el-icon-s-promotion" @click="dialogVisible=true">新增
                </el-button>
                <el-popconfirm
                        confirm-button-text='好的'
                        cancel-button-text='不用了'
                        icon="el-icon-info"
                        icon-color="red"
                        @confirm="removeLiterature()"
                        title="您确定要删除选中的数据吗？"
                >
                    <el-button size="medium" class="el-icon-delete" slot="reference" style="margin-left: 10px">删除
                    </el-button>
                </el-popconfirm>
            </el-row>
        </div>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr class="q_xuhao">
                    <td>序号</td>
                    <td>日期</td>
                    <td>名称及内容提要</td>
                    <td>出版、登载获奖或在学术会议上交流情况</td>
                    <td>合（独）著、译</td>
                </tr>
                </thead>
                <tbody v-if="literatureData.length>0">
                <tr v-for="(item,index) in literatureData">
                    <td>
                        <input type="checkbox" @change="selectItem(item.id)">
                        <span>{{index+1}}</span>
                    </td>
                    <td>{{item.frqnyr}}</td>
                    <td>
                        <el-popover trigger="hover">
                            <span>{{item.fmcjnrty}}</span>
                            <div slot="reference" class="name-wrapper ellipsis max_width">
                                {{item.fmcjnrty}}
                            </div>
                        </el-popover>
                    </td>
                    <td>
                        <el-popover trigger="hover">
                            <span>{{item.fcbdzhjhzxshysjlqk}}</span>
                            <div slot="reference" class="name-wrapper ellipsis max_width">
                                {{item.fcbdzhjhzxshysjlqk}}
                            </div>
                        </el-popover>
                    </td>
                    <td>
                        <el-popover trigger="hover">
                            <span>{{item.fhdzy}}</span>
                            <div slot="reference" class="name-wrapper ellipsis medium_width">
                                {{item.fhdzy}}
                            </div>
                        </el-popover>
                    </td>
                </tr>
                </tbody>
                <tr v-else>
                    <td colspan="6">
                        <el-empty></el-empty>
                    </td>
                </tr>
            </table>
        </div>
        <!--    弹出框    -->
        <el-dialog
                title="著作、论文及重要技术报告"
                :visible.sync="dialogVisible"
                width="30%"
                :before-close="handleClose"
                center>
            <el-form :model="literature" :rules="rules" ref="literature"
                     label-width="100px" class="demo-ruleForm">
                <el-form-item label="名称及内容" prop="fmcjnrty">
                    <el-input v-model="literature.fmcjnrty" palceholder="名称及内容提要"></el-input>
                </el-form-item>
                <el-form-item label="出版、登载" prop="fcbdzhjhzxshysjlqk">
                    <el-input v-model="literature.fcbdzhjhzxshysjlqk" palceholder="出版、登载获奖或在学术会议上交流情况"></el-input>
                </el-form-item>
                <el-form-item label="合（独）著、译" prop="fhdzy">
                    <el-input v-model="literature.fhdzy" palceholder="合（独）著、译"></el-input>
                </el-form-item>
                <el-form-item label="著作日期" required>
                    <el-form-item prop="frqnyr">
                        <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd"
                                        v-model="literature.frqnyr"
                                        style="width: 100%;"></el-date-picker>
                    </el-form-item>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('literature')">提交</el-button>
                    <el-button type="primary" @click="resetForm('literature')">重置</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <!--        -->
        <div class="q_sub ">
            <el-pagination
                    background
                    layout="prev, pager, next"
                    :current-page.sync="currentPage"
                    :hide-on-single-page="hidePage"
                    :page-size="pageSize"
                    :total="total"
                    @current-change="queryLiterature">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    import "../assets/samecss/same.css"

    export default {
        name: "LiteratureRecord",
        created() {
            this.queryLiterature()
        },
        methods: {
            //提示关闭
            handleClose(done) {
                this.$confirm('确认关闭？').then(_ => {
                    done();
                }).catch(_ => {
                });
            },
            //提交表单
            submitForm(formName) {
                let that = this;
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        that.$http.post('/paper/paperadd', that.literature).then(res => {
                            that.$message.success('提交成功！')
                            that.queryLiterature();
                            that.resetForm(formName);
                        })
                    } else {
                        return false;
                    }
                });
            },
            //选中数据项
            selectItem(id) {
                let index = this.ids.indexOf(id)
                if (index > -1) {
                    this.ids.splice(index, index + 1)
                } else {
                    this.ids.push(id)
                    console.log(this.ids)
                }
            },
            //删除数据
            removeLiterature() {
                let that = this;
                if (that.ids.length == 0) {
                    that.$message.warning('你还没有选择需要删除的数据')
                    return
                }
                that.$http.post("/paper/paperdle", that.ids).then(res => {
                    that.$message.success("删除成功");
                    that.queryLiterature();
                    that.ids = [];
                })
            },
            //查询
            queryLiterature() {
                let that = this;
                that.$http.get("/paper/paperslt", {
                    params: {
                        currentPage: that.currentPage,
                        pageSize: that.pageSize
                    },
                }).then(res => {
                    that.literatureData = res.data.list
                    that.currentPage = res.data.currentPage
                    // console.log(res)
                    that.total = res.data.total
                })
            },
            //清空表单
            resetForm(formName) {
                this.literature = {};
                this.$refs[formName].clearValidate();
            }
        },

        data() {
            return {
                ids: [],
                currentPage: 1,
                pageSize: 10,
                hidePage: true,
                total: 1,
                dialogVisible: false,
                literatureData: [],
                literature: {
                    frqnyr: '',
                    fmcjnrty: '',
                    fcbdzhjhzxshysjlqk: '',
                    fhdzy: '',
                },
                rules: {
                    frqnyr: [
                        {required: true, message: '请选择开始日期', trigger: 'blur'}
                    ],
                    fmcjnrty: [
                        {required: true, message: '名称及内容提要', trigger: 'blur'},
                        {min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur'}
                    ],
                    fcbdzhjhzxshysjlqk: [
                        {required: true, message: '出版、登载获奖或在学术会议上交流情况', trigger: 'blur'},
                        {min: 1, max: 100, message: '长度在 3 到 50 个字符', trigger: 'blur'}
                    ],
                    fhdzy: [
                        {required: true, message: '合（独）著、译', trigger: 'blur'},
                        {min: 5, max: 100, message: '长度在 5 到 50 个字符', trigger: 'blur'}
                    ]
                }
            }
        }
    }
</script>

<style scoped>

</style>
